<template>
  <div class="cus-base-info">
    <div class="head-content">
      <div class="avatar">
        <img class="avatar-img" :src="customerInfo.headerImg || headPicture" alt="" @error="(event)=>{event.srcElement.src=headPicture}">
        <img class="member-logo" v-if="customerInfo.memberLogo" :src="customerInfo.memberLogo" alt="">
      </div>
      <div class="ext-info">
        <div class="title">{{ customerInfo.phone ?? '--' }}</div>
        <div><span class="ext-lable">用户ID</span>
          <span>{{ customerInfo.id }}</span>
        </div>
        <div><span class="ext-lable">注册时间</span>
          <span>{{ $filters.dateFormat(customerInfo.createTime) }}</span>
        </div>
      </div>

    </div>
    <div class="body-content">
      <div class="card">
        <div class="title">基本信息</div>
        <div class="row">
          <span class="lable">所属机构</span>
          <span class="row-text">{{ customerInfo.insName }}</span>
        </div>
        <div class="row">
          <span class="lable">手机号码</span>
          <span class="row-text">{{ customerInfo.phone ?? '--' }}</span>
        </div>
        <div class="row">
          <span class="lable">用户昵称</span>
          <span class="row-text">{{ customerInfo.nickName ?? '--' }}</span>
        </div>
        <div class="row">
          <span class="lable">客户ID</span>
          <span class="row-text">{{ customerInfo.unionId }}</span>
        </div>
        <div class="row">
          <span class="lable">当前会员等级</span>
          <span class="row-text">{{ customerInfo.memberName ?? '--' }}</span>
        </div>
        <div class="row">
          <span class="lable">等级更新时间</span>
          <span class="row-text">{{ customerInfo.getGradleLastTime?$filters.dateFormat(customerInfo.getGradleLastTime):'--' }} </span>
        </div>
        <div class="row">
          <span class="lable">当前成长值</span>
          <span class="row-text">{{ customerInfo.growth ?? '--' }}</span>
        </div>
      </div>
      <div class="card" style="margin-bottom: 0;">
        <div class="title">资产信息</div>
        <div class="row" v-for="item in currencyInfo" :key="item.id">
          <span class="lable">当前/使用/累计{{ item.currencyName || '' }}</span>
          <span class="row-text">{{ item.totalAvailable ?? '--' }}/{{ item.totalConsume ?? '--' }}/{{
            item.totalReceive ?? "--" }}</span>
        </div>

        <div class="row">
          <span class="lable">领取/使用/过期优惠券</span>
          <span
            class="row-text">{{ couponInfo.receiveNum ?? '--' }}/{{ couponInfo.usedNum ?? '--' }}/{{ couponInfo.expiredNum ?? "--"
            }}</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import CustomerApi from "@/api/customerApi";
import headPicture from "@/assets/images/_picture.png";
const props = defineProps({
  customerInfo: {
    type: Object,
    default: () => ({})
  },
  currencyInfo: {
    type: Object,
    default: () => []
  }
})
const id = useRoute().params.id
const couponInfo = ref({ expiredNum: 0, receiveNum: 0, usedNum: 0 })
//获取卡券信息
const getCouponInfo = async (id) => {
    const res = await CustomerApi.getCouponInfo({ id: id })
  if (res.code == 200) {
    if (res.payload) {
      couponInfo.value = res.payload
    }
  }
}
watch(()=>props.customerInfo, () => {
  if (props.customerInfo.id) {
    getCouponInfo(props.customerInfo.id)
  } else {
    couponInfo.value = { expiredNum: 0, receiveNum: 0, usedNum: 0 }
  }
})
onMounted(() => {
  getCouponInfo(id)
})
</script>
<style lang="scss" scoped>
.cus-base-info {
  // height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  width: 420px;
  flex-shrink: 0;
  padding: 20px;
  margin-left: 20px;
  margin-top: 20px;
  box-sizing: border-box;
  border-radius: 4px;
  box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.1);
}

.head-content {
  display: flex;
  position: relative;
  padding-bottom: 12px;

  .avatar {
    width: 80px;
    height: 80px;
    overflow: hidden;
    border-radius: 50%;
    border: 1px solid #f7f7f7;

    .avatar-img {
      width: 100%;
      height: 100%;
    }

    .member-logo {
      position: absolute;
      width: 74px;
      height: 22px;
      left: 0;
      bottom: 4px;
    }
  }

  .ext-info {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding-top: 4px;
    justify-content: space-around;
    margin-left: 16px;
    color: #666666;
    font-size: 15px;

    .ext-lable {
      margin-right: 4px;
    }
  }
}

.lable {
  color: #666666;
  font-size: 15px;
}

.title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #303133;
  font-size: 18px;
  font-weight: 700;
}

.row-text {
  margin-left: 12px;
  font-size: 15px;
  font-weight: 500;
  color: #333333;
}

.body-content {
  .card {
    margin-top: 40px;
  }

  .row {
    margin-top: 12px;
  }
}
</style>